﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.ComponentModel;

namespace outREACH.App_Code
{
    [DataObject]
    public class Countries
    {
        [DataObjectField(true, true)]
        public string Country { get; set; }


        


          [DataObjectMethod(DataObjectMethodType.Select)]
        public static List<Countries> GetCountries()
        {
            SqlConnection conn = null;
            conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["outreachdbConnectionString"].ConnectionString;
            conn.Open();
            SqlCommand comm = new SqlCommand();
            comm.Connection = conn;
            comm.CommandText = "select * from Countries";
            SqlDataReader dr = comm.ExecuteReader();
            List<Countries> list = new List<Countries>();
            while (dr.Read())
            {
                Countries u = new Countries();
                u.Country = (String)dr["Countries"];
                list.Add(u);
            }
            return list;
        }
        public static List<Countries> ListAll()
        {
           
            List<Countries> results = new List<Countries>();
            SqlConnection conn = new SqlConnection();

            try
            {
                //do sql operation
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["outreachdbConnectionString"].ConnectionString;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "Select * from Countries";
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    Countries u = new Countries();
                    u.Country = (String)dr["Countries"];

                    results.Add(u);


                }
                dr.Close();




            }
            catch (SqlException e)
            {
                /*if error we will throw exception to you */
                throw e;


            }
            finally
            {
                /*no matter if pass or fail, we need to
                 * close the database connection */

                conn.Close();

            }
            return results;

        }

        
    }
}